package com.zjc.yohoshop.mvp.view.custom;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * 首页折扣前的TextView
 * 中间一条斜线
 */
@SuppressLint("AppCompatCustomView")
public class MyTextViewHomeOriginalPrice  extends TextView {


    private int sumHeight;//获取控件总高
    private int sumWidth;//获取控件总宽

    private Paint paint_line;//斜线画笔


    public MyTextViewHomeOriginalPrice(Context context) {
        super(context);
    }

    public MyTextViewHomeOriginalPrice(Context context, AttributeSet attrs) {  //如没有  AttributeSet 无法再XMl  中使用  设置自定义属性
        super(context, attrs);
        initPaint();
    }

    //初始化画笔
    private void initPaint() {
        //初始化背景画笔
        paint_line = new Paint();
        paint_line.setColor(Color.parseColor("#CCCCCC"));
        paint_line.setStyle(Paint.Style.FILL);
        paint_line.setStrokeWidth(3);

    }

    public MyTextViewHomeOriginalPrice(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public MyTextViewHomeOriginalPrice(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        sumHeight = getMeasuredHeight();
        sumWidth = getMeasuredWidth();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //绘制斜线
        canvas.drawLine(0, sumHeight / 2, sumWidth, sumHeight / 2 + 2, paint_line);



    }


}
